package bombermanGame;


import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.AbstractComponent;
import org.newdawn.slick.gui.ComponentListener;
import org.newdawn.slick.gui.MouseOverArea;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class MainMenuState extends BasicGameState implements ComponentListener {
	
	public static int ID = 1;
	/** the game holding this state*/
	private StateBasedGame game;
	/** the container of the game */
	private GameContainer container;
	private Image background;
	private Image logo;
	private Image bombermanLogo;
	private Image playButton;
	private Image registerButton;
	private Image loginButton;
	private Image exitButton;
	
	private MouseOverArea playButtonMouseOverArea;
	private MouseOverArea registerButtonMouseOverArea;
	private MouseOverArea loginButtonMouseOverArea;
	private MouseOverArea exitButtonMouseOverArea;
	

	@Override
	public void init(GameContainer container, StateBasedGame game)
			throws SlickException {
		this.game = game;
		this.container = container;
		
		background = new Image("/images/GameMenuImages/background.jpg");
		logo = new Image("/images/GameMenuImages/logo.png");	
		bombermanLogo = new Image("images/GameMenuImages/bombermanLogo.gif");
		
		playButton = new Image("images/GameMenuImages/playButton.png");
		registerButton = new Image("images/GameMenuImages/registerButton.png");
		loginButton = new Image("images/GameMenuImages/loginButton.png");
		exitButton = new Image("images/GameMenuImages/exitButton.png");
		
		// play button area
		playButtonMouseOverArea = new MouseOverArea(container, playButton, 400, 270, playButton.getWidth(), playButton.getHeight(), this);
		playButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		playButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
		
		// register button area
		registerButtonMouseOverArea = new MouseOverArea(container, registerButton, 400, 320, registerButton.getWidth(), registerButton.getHeight(), this);
		registerButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		registerButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
		
		// login button area
		loginButtonMouseOverArea = new MouseOverArea(container, loginButton, 400, 370, loginButton.getWidth(), loginButton.getHeight(), this);
		loginButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		loginButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
		
		// exit button area
		exitButtonMouseOverArea = new MouseOverArea(container, exitButton, 400, 420, exitButton.getWidth(), exitButton.getHeight(), this);
		exitButtonMouseOverArea.setNormalColor(new Color(1, 1, 1, 0.8f));
		exitButtonMouseOverArea.setMouseOverColor(new Color(1, 1, 1, 0.99f));
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		background.draw(0, 0);
		logo.draw(70, 100);
		bombermanLogo.draw(140, 220);
		
		playButtonMouseOverArea.render(container, g);
		registerButtonMouseOverArea.render(container, g);		
		loginButtonMouseOverArea.render(container, g);
		exitButtonMouseOverArea.render(container, g);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getID() {
		return ID;
	}

	@Override
	public void componentActivated(AbstractComponent source) {
		if(source == playButtonMouseOverArea) {
			game.enterState(GameMenuState.ID);
		}
		else if(source == registerButtonMouseOverArea) {
			game.enterState(RegisterMenuState.ID);
		}
		else if(source == loginButtonMouseOverArea) {
			game.enterState(LoginMenuState.ID);
		}
		else if(source == exitButtonMouseOverArea) {
			container.exit();
		}
	}

}
